package com.ytf.test.eighth;

/**
 * @author: YTF
 * @date: 2025/1/24 15:51
 * @version: 1.0
 * @description: 覆盖缺陷
 */
public class PrivateOverride {
    private void f(){
        System.out.println("PrivateOverride.f() private");
    }

    public static void main(String[] args) {
        // 向上转型
        PrivateOverride privateOverride = new Derived();
        privateOverride.f();
        /**
         * Output:
         * PrivateOverride.f() private
         * 这里没有覆盖成功 重写失败的原因是 父类中f()方法是私有的 private 默认是final 方法无法被重写
         * 建议子类方法名不要和父类私有方法名相同
         */
    }
}
class Derived extends PrivateOverride{
    // @Override
    public void f(){
        System.out.println("Derived.f() public");
    }
}
